/*
 * TMQL4J - Javabased TMQL Engine
 * 
 * Copyright: Copyright 2010 Topic Maps Lab, University of Leipzig. http://www.topicmapslab.de/    
 * License:   Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0.html
 * 
 * @author Sven Krosse
 * @email krosse@informatik.uni-leipzig.de
 *
 */
package de.topicmapslab.tmql4j.components.processor.results.model;

import java.util.Map;

import de.topicmapslab.tmql4j.components.processor.core.IContext;
import de.topicmapslab.tmql4j.components.processor.core.QueryMatches;
import de.topicmapslab.tmql4j.exception.TMQLRuntimeException;

/**
 * Interface definition of a result processor. A result processor transform the
 * tuple sequences generated by the interpretation task to a {@link IResultSet}.
 * 
 * @author Sven Krosse
 * @email krosse@informatik.uni-leipzig.de
 * 
 */
public interface IResultProcessor {

	/**
	 * Method returns the result of the result processor. The result represents
	 * the generated {@link IResultSet} containing all results of querying
	 * process.
	 * 
	 * @param <T>
	 *            the type of contained results
	 * @return the generated result set
	 */
	public <T extends IResultSet<?>> T getResultSet();

	/**
	 * Method starts the internal execution. The result processor will transform
	 * the querying results to a {@link IResultSet}.
	 * 
	 * @param context
	 *            the querying context
	 * @param matches
	 *            the querying results
	 * @throws TMQLRuntimeException
	 *             thrown if {@link IResultSet} class can not be instantiate or
	 *             a error happened during transformation task
	 */
	public void proceed(IContext context, QueryMatches matches) throws TMQLRuntimeException;

	/**
	 * Method to overwrite the result set class used to create the querying
	 * result
	 * 
	 * @param clazz
	 *            the new result set class
	 */
	public void setResultType(Class<? extends IResultSet<?>> clazz);

	/**
	 * Changing the internal state of auto reduction mechanism. If value set to
	 * <code>true</code> the result processor transform the results to a
	 * two-dimensional construct. If the value is <code>false</code> the results
	 * may contain collections as value.
	 * 
	 * @param autoReduction
	 *            the auto reduction mechanism.
	 */
	public void setAutoReduction(boolean autoReduction);

	/**
	 * Setting an alias for the given index.
	 * 
	 * @param index
	 *            the index
	 * @param alias
	 *            the alias
	 */
	public void setColumnAlias(final int index, final String alias);

	/**
	 * Returns the index of the alias
	 * 
	 * @param alias
	 *            the alias
	 * @return the index or <code>-1</code> if the alias is unknown.
	 */
	public int getIndexOfAlias(final String alias);

	/**
	 * Checks if the given alias is known by the result processor.
	 * 
	 * @param alias
	 *            the alias
	 * @return <code>true</code> if the alias is known, <code>false</code>
	 *         otherwise.
	 */
	public boolean isKnownAlias(final String alias);
	
	/**
	 * Returns the aliases for the index set by the use of AS clauses
	 * @return the alias
	 */
	public Map<Integer, String> getAliases();

}
